# -*- coding: utf-8 -*-
"""
@Project ：weather 
@File    ：config.py
@Author: guzain
@Date:  2025/7/7 12:41:39
@Email： GZA5210@163.com
@Description: 
"""
import configparser
import os

# 创建配置解析器
config = configparser.ConfigParser()
# 保持配置项名称的大小写
config.optionxform = str

city_config = configparser.ConfigParser(strict=False)
# 保持城市配置项名称的大小写
city_config.optionxform = str

# 获取配置文件路径
config_path = os.path.join(os.path.dirname(__file__), 'config.ini')
city_config_path = os.path.join(os.path.dirname(__file__), 'City.ini')

# 读取配置文件
config.read(config_path, encoding='utf-8')
city_config.read(city_config_path, encoding='utf-8')

# API_KEYS部分
GAODEAPI = config.get('API_KEYS', 'GAODEAPI', fallback='')
GAODEAPI = GAODEAPI.strip().strip('"').strip("'")
WEATHER_KEY = config.get('API_KEYS', 'WEATHER_KEY', fallback='')
WEATHER_KEY = WEATHER_KEY.strip().strip('"').strip("'")
TIANAPI_KEY = config.get('API_KEYS', 'TIANAPI_KEY', fallback='')
TIANAPI_KEY = TIANAPI_KEY.strip().strip('"').strip("'")
SENDKEY = config.get('API_KEYS', 'SENDKEY', fallback='')
SENDKEY = SENDKEY.strip().strip('"').strip("'")

# EMAIL部分
EMAIL = config.get('EMAIL', 'EMAIL', fallback='XX@163.com')
EMAIL_PASSWORD = config.get('EMAIL', 'EMAIL_PASSWORD', fallback='')
EMAIL_PASSWORD = EMAIL_PASSWORD.strip().strip('"').strip("'")
SMTP_SERVER = config.get('EMAIL', 'SMTP_SERVER', fallback='smtp.163.com')
SMTP_PORT = config.getint('EMAIL', 'SMTP_PORT', fallback=465)

# CITY部分
USE_NETWORK_CITY = config.getboolean('CITY', 'USE_NETWORK_CITY', fallback=True)
FIXED_CITY = config.get('CITY', 'FIXED_CITY', fallback='北京')
FIXED_CITY = FIXED_CITY.strip().strip('"').strip("'")

# QUOTES部分
USE_NETWORK_ENGLISH = config.getboolean('QUOTES', 'USE_NETWORK_ENGLISH', fallback=True)
USE_NETWORK_WYY = config.getboolean('QUOTES', 'USE_NETWORK_WYY', fallback=True)

# WECHAT_WORK部分
WECHAT_WORK_WEBHOOK = config.get('WECHAT_WORK', 'WECHAT_WORK_WEBHOOK', fallback='')
WECHAT_WORK_WEBHOOK = WECHAT_WORK_WEBHOOK.strip().strip('"').strip("'")

# DINGTALK部分
DINGTALK_WEBHOOK = config.get('DINGTALK', 'DINGTALK_WEBHOOK', fallback='')
DINGTALK_WEBHOOK = DINGTALK_WEBHOOK.strip().strip('"').strip("'")
DINGTALK_SECRET = config.get('DINGTALK', 'DINGTALK_SECRET', fallback='')
DINGTALK_SECRET = DINGTALK_SECRET.strip().strip('"').strip("'")

# 获取城市ID映射
CITY_ID_MAP = {}
if city_config.has_section('CITY_IDS'):
    CITY_ID_MAP = dict(city_config['CITY_IDS'])
    # 去除城市ID中的引号
    for city_name, city_id in CITY_ID_MAP.items():
        CITY_ID_MAP[city_name] = city_id.strip().strip('"').strip("'")